import sys
import os
from fastapi import APIRouter, HTTPException
from pydantic import BaseModel
from typing import List

# 添加项目根目录到Python路径
backend_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, backend_path)

# 修复导入路径
from api import email_api

router = APIRouter()

class EmailRequest(BaseModel):
    sender_email: str
    sender_password: str
    recipients: List[str]
    cc_recipients: List[str]
    input_file: str

class EmailResponse(BaseModel):
    status: str
    message: str

@router.post("/send-report", response_model=EmailResponse)
async def send_fault_report(email_request: EmailRequest):
    """发送故障报告邮件"""
    try:
        result = email_api.send_fault_report(
            sender_email=email_request.sender_email,
            sender_password=email_request.sender_password,
            recipients=email_request.recipients,
            cc_recipients=email_request.cc_recipients,
            input_file=email_request.input_file
        )
        return result
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))